/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rpg;

import java.awt.Graphics2D;
import java.awt.Image;
import java.util.List;
import javax.swing.ImageIcon;
import rpg.tools.FileManager;

/**
 *
 * @author Emmanouil Samatas
 */
public class Dungeon {

    private List<String> dungeonMap;
    private String wallImageFileName = "wall.png";
    private String enemyFileName = "military.gif";
    private Image wall, military;
    private int[] playerPosition = new int[2];

    public Dungeon(int level) {
        FileManager fm = FileManager.getInstance();
        this.dungeonMap = fm.loadMap(level);

        ImageIcon ii = new ImageIcon(this.getClass().getResource(wallImageFileName));
        wall = ii.getImage();
        ImageIcon bi = new ImageIcon(this.getClass().getResource(enemyFileName));
        military = bi.getImage();
    }

    public Image getWall() {
        return wall;
    }

    ;
    
    public Image getMilitary() {
        return military;
    }

    public String getMapPoint(int x, int y) {
        String mapPoint = dungeonMap.get(y).substring(x, x + 1);
        return mapPoint;
    }
    
    public void setMapPoint(int x,int y , char state){
        StringBuilder mapLine = new StringBuilder(dungeonMap.get(y));
        mapLine.setCharAt(x,state);
        dungeonMap.set(y,mapLine.toString());
        
    }

    public List<String> getMap() {
        return this.dungeonMap;
    }

    /*
     * Returns the initianl player position in the map.
     */
    public int[] getPlayerPoint() {
        for (int y = 0; y < dungeonMap.size(); y++) {
            for (int x = 0; x < dungeonMap.get(y).length(); x++) {
                if (getMapPoint(x, y).equals("p")) {
                    playerPosition[0] = x;
                    playerPosition[1] = y;

                }
            }
        }
        return playerPosition;
    }
}
